<script setup>
import {Setting} from "@element-plus/icons-vue";
import {onBeforeMount, ref} from "vue";
import request from "@/utils/request";
import {useRouter} from "vue-router";
let username = ref("")
const router = useRouter()

function toLogin(){
  router.replace({path:"/login"})
}

onBeforeMount(()=>{
  request.get("http://localhost:8090/user/getUserNameByUid")
      .then(res=>{
        if(res.data.code === 200)username.value = res.data.data
      })
      .catch(err=>{
        console.log(err)
      })
})
</script>

<template>
  <div class="toolbar">
    <el-dropdown>
      <el-icon style="margin-right: 10px; margin-top: 1px" size="20">
        <setting />
      </el-icon>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item @click="toLogin">退出登录</el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
    <span style="font-size: 20px">{{username}}</span>
  </div>
</template>

<style scoped>
.toolbar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  right: 20px;
}
</style>